import React, { Component } from 'react';
import { StyleSheet, Text, View, SafeAreaView, Button, StatusBar } from 'react-native';

export default class Profile extends Component {
  render() {
    const { navigation } = this.props;
    const msg = navigation.getParam('msg', 'NO-MSG');
    const itemId = navigation.getParam('itemId', 'NO-ID');
    return (
      <SafeAreaView style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: '#ecf0f1' }}>
        <StatusBar barStyle='dark-content' backgroundColor='#ecf0f1' />
        <Text>Home Screen</Text>
        <Text>itemId: {JSON.stringify(itemId)}</Text>
        <Text>msg: {JSON.stringify(msg)}</Text>
        <Button
          title='Go to Me 带参数'
          onPress={() => {
            /* 1. Navigate to the Details route with params */
            this.props.navigation.navigate('Me', {
              itemId     : 86,
              otherParam : 'anything you want here',
              data       : { id: 123 },
              cb         : function(data) {
                alert('回来了' + JSON.stringify(data));

                navigation.actions.setParams('msg', { msg: '回调回来改变值' });
                const msg = navigation.getParam('msg', 'NO-ID');
                console.log('msg', msg);
                console.log('navigation', navigation);
              }
            });
          }}
        />
      </SafeAreaView>
    );
  }
}

const styles = StyleSheet.create({
  container    : {
    flex            : 1,
    justifyContent  : 'center',
    alignItems      : 'center',
    backgroundColor : '#F5FCFF'
  },
  welcome      : {
    fontSize  : 20,
    textAlign : 'center',
    margin    : 10
  },
  instructions : {
    textAlign    : 'center',
    color        : '#333333',
    marginBottom : 5
  }
});
